package Validators;

import javax.enterprise.context.Dependent;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.inject.Named;

/**
 *
 * @author Rune <your.name at your.org>
 */
@Named(value = "val")
@Dependent
public class Validator {

    /**
     * Creates a new instance of Validator
     */
    public Validator() {
    }

    public void validateVol(FacesContext context, UIComponent toValidate, Object value) {
        String email = (String) value;

        if (email.indexOf('@') == -1) {
            ((UIInput) toValidate).setValid(false);

            FacesMessage message = new FacesMessage("Invalid input vol");
            context.addMessage(toValidate.getClientId(context), message);
        }
    }
}
